import {
  Column,
  Entity,
  Generated,
  ManyToMany,
  ManyToOne,
  PrimaryColumn,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { User } from './user.entity';
import { BaseEntity } from '../entities/base.entity';
import * as crypto from 'crypto';
import { Poll } from './poll.entity';
@Entity('post')
export class Post extends BaseEntity {
  constructor() {
    super();
    this.id = crypto.randomBytes(8).toString('hex'); // 生成一个8字节（16个十六进制字符）的随机字符串作为id
  }
  @PrimaryColumn({ length: 225 })
  id: string;

  @Column()
  title: string;

  @Column({ type: 'simple-array', nullable: true })
  imgUrlList: string[];

  @Column({ type: 'text', comment: '投票内容' })
  content: string;

  @ManyToOne(() => Poll, (poll) => poll.post, { onDelete: 'SET NULL' })
  poll: Poll;

  // @Column()
  // pollId: string; // 将投票项目ID作为外键存储
}
